use std::collections::HashSet;

use scraper::{Html, Selector};

fn main() {
    let document = Html::parse_document(&std::fs::read_to_string("index.html").unwrap());

    let selector = Selector::parse(r#"a[class="reference internal"]"#).unwrap();

    let mut set = HashSet::new();

    let mut ret = Vec::new();

    // 遍历匹配到的所有元素
    for element in document.select(&selector) {
        let url = element.attr("href").unwrap().split('#').nth(0).unwrap();

        if !set.contains(url) {
            //println!("{:?}", element);
            ret.push(url);
            set.insert(url);
        }
    }

    for url in ret.iter() {
        println!("{:?}", url);
    }
}
